package com.koron.car.web.motorcade.controller;

import com.alibaba.fastjson.JSON;
import com.koron.bean.base.Response;
import com.koron.car.web.motorcade.bean.Motorcade;
import com.koron.car.web.motorcade.service.MotorcadeService;
import com.koron.common.core.config.ThreadLocalContext;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.koron.ebs.mybatis.ADOConnection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author twcao
 * @title: MotorcadeController
 * @projectName GDH_EAM_V2
 * @description: 车队
 * @date 2022/3/210:54
 */
@Slf4j
@Api(tags = "车辆管理-车队")
@RestController
@RequestMapping("/motorcade")
public class MotorcadeController {

    @Autowired
    private MotorcadeService motorcadeService;

    @GetMapping("/queryList")
    @ApiOperation("车队列表查询")
    public Response<List<Motorcade>> queryList(@RequestParam(required = false) String name) {
        log.info("车队列表查询, name = {}", name);
        List<Motorcade> bean = ADOConnection.runTask(ThreadLocalContext.get().getCurrDs(), motorcadeService, "queryList", List.class, name);
        return Response.ok(bean);
    }

    @GetMapping("/saveOrUpdate")
    @ApiOperation("修改车队名字（不可重名），更新：有id、名字， 新增：无id、有名字")
    public Response<Motorcade> saveOrUpdate(Motorcade motorcade) {
        log.info("修改车队名字, motorcade = {}", JSON.toJSONString(motorcade));
        motorcade = ADOConnection.runTask(ThreadLocalContext.get().getCurrDs(), motorcadeService, "saveOrUpdate", Motorcade.class, motorcade);
        return Response.ok(motorcade);
    }

    @GetMapping("/delete")
    @ApiOperation("根据id删除车队")
    public Response<Motorcade> delete(@RequestParam String id) {
        log.info("根据id删除车队, id = {}", id);
        ADOConnection.runTask(ThreadLocalContext.get().getCurrDs(), motorcadeService, "hiddenById", Boolean.class, id);
        return Response.ok();
    }
}
